package raf;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
 * 将user。txt文件所有用户记录读取出来并输出到控制台
 */
public class ShowAllUserDemo {
    public static void main(String[] args) throws IOException {
            RandomAccessFile raf = new RandomAccessFile("user.txt", "rw");
        //读取用户名
        for (int i = 0; i < raf.length() / 100; i++) {
            byte[] data = new byte[32];
            //读取用户名
            raf.read(data);
            String username = new String(data, "UTF-8").trim();
            System.out.println(username);
            //读取密码
            raf.read(data);
            String password = new String(data, "UTF-8").trim();
            System.out.println(password);
            //读取昵称
            raf.read(data);
            String nickname = new String(data, "UTF-8").trim();
            System.out.println(nickname);
            //读取年龄
             int age=raf.readInt();
            System.out.println(username+","+password+","+nickname+","+age);
        }
        raf.close();
    }
}